package team3.tracking.util;

public class PositionInfo {
	   
//This function will serialized all the data
	public static byte[] serializeData(ClientData input){

		byte[] outputByteStream;

		String outputString;
		try{
			outputString = 	input.clientID + "#" + Double.toString(input.latitude) + "#" + Double.toString(input.longitude)
			+ "#" + Long.toString(input.timeStamp) 
			+ "#" + Double.toString(input.predictionVectorX)+ "#" + Double.toString(input.predictionVectorY)+ "#";
		}
		catch(NumberFormatException e){
			outputString = "";
		}
		outputByteStream = outputString.getBytes();

		return(outputByteStream);
	}
	//This function will deseralized and sent data back in the form on ClientData
	public static ClientData deserializeData(String input){
		String [] tokens;
		ClientData cData = new ClientData();
		System.out.println("Input : "+input);
		tokens = input.split("#");
		System.out.println(tokens.length);
		if(tokens.length >= 6 ){
			cData.setClientID(tokens[0]);
			cData.setLatitude(Double.parseDouble(tokens[1]));			
			cData.setLongitude(Double.parseDouble(tokens[2]));
			cData.setTimeStamp(Long.parseLong(tokens[3]));
			cData.setPredictionVectorX(Double.parseDouble(tokens[4]));
			cData.setPredictionVectorY(Double.parseDouble(tokens[5]));	
		}


		return(cData);
	}
	

}
